package cn.zd.core.service.impl;

import cn.zd.core.dao.BaseDao;
import cn.zd.core.entity.IdEntity;
import cn.zd.core.service.BaseService;

import java.util.List;

/**
 * 基础服务接口实现
 *
 * @author TMAC
 * @email 2466721401@qq.com
 */
public abstract class BaseServiceImpl<T extends IdEntity> implements BaseService<T> {

    protected abstract BaseDao<T> getDao();

    @Override
    public T create(T entity) {
        int id = getDao().insert(entity);
        entity.setId(id);
        return entity;
    }

    @Override
    public T save(T entity) {
        getDao().update(entity);
        return entity;
    }

    @Override
    public int update(T entity) {
        return getDao().update(entity);
    }

    @Override
    public int remove(Integer id) {
        return getDao().deleteById(id);
    }

    @Override
    public T get(Integer id) {
        return getDao().get(id);
    }

    @Override
    public List<T> all() {
        return getDao().all();
    }
}
